package com.zdzx.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdzx.common.result.PageInfo;
import com.zdzx.common.result.PageUtil;
import com.zdzx.common.result.Result;
import com.zdzx.common.result.ResultCode;
import com.zdzx.common.result.ResultUtil;
import com.zdzx.mapper.TransactionRecordMapper;
import com.zdzx.model.service.content.vo.TransactionRecord;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

	
@Api(tags = "交易记录")
@RestController
@RequestMapping("/admin")
public class TransactionController{
	
	@Autowired
	private TransactionRecordMapper transactionRecordMapper;
	@ApiOperation(value = "获取列表", notes = "")
	@GetMapping("/transaction/record")
	public Result<PageInfo<TransactionRecord>> list(
			@ApiParam("") @RequestParam(value = "pageNum", required = false) Integer pageNum,
			@ApiParam("") @RequestParam(value = "pageSize", required = false) Integer pageSize,
			@ApiParam("") @RequestParam(value = "username", required = false) String username){
		Page<TransactionRecord> page=new Page<TransactionRecord>(pageNum,pageSize);
		QueryWrapper<TransactionRecord> queryWrapper=new QueryWrapper<TransactionRecord>();
		if(!StringUtils.isEmpty(username))
			queryWrapper.eq("username", username);
		queryWrapper.orderByDesc("create_time");
		IPage<TransactionRecord> info = transactionRecordMapper.selectPage(page,queryWrapper);
		PageInfo<TransactionRecord> data = PageUtil.data(info.getPages(), info.getCurrent(), info.getTotal(), info.getRecords());
		return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(),null, data);
	}
	
}
